//
//  LWMainViewController.swift
//  微博
//
//  Created by mac on 17/5/16.
//  Copyright © 2017年 mac. All rights reserved.
//

import UIKit

class LWMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.backgroundColor = UIColor.orange
        
        
        //使用KVC给只读属性赋值
        let LWtab = LWTableBar()
        
        //设置代理
        LWtab.lwDelegate = self
        
        setValue(LWtab, forKey: "tabBar")
        
        LWtab.composeBtnClouser = {[weak self] in
            
            print("闭包过来的")
            
            
        }
        
        
        
        
     //   self.tabBar = LWTableBar
        
        
        
        
        
        //设置titnColor    统一设置选中颜色（越早越好）
        UITabBar.appearance().tintColor = UIColor.orange
        
        //添加子视图控制器
        addChildViewController(childController: LWHomeTableViewController(), title: "首页", imageName: "tabbar_home")
        
        addChildViewController(childController: LWMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        
        addChildViewController(childController: LWDiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        
        addChildViewController(childController: LWPrefileTableViewController(), title: "我的", imageName: "tabbar_profile")
        
        
    }
    
    //添加子视图控制器的方法重载
    func addChildViewController(childController: UIViewController, title:String, imageName:String ) {
        
        //设置tab的图片
        childController.tabBarItem.image = UIImage(named: imageName)
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")
        
        //设置tab的标题
        childController.tabBarItem.title = title
        
        //设置顶部的标题
        childController.navigationItem.title = title
        
        
        //创建导航控制
        let nav = UINavigationController(rootViewController: childController)
        
        
        //添加子视图控制器
        addChildViewController(nav)
        
        
        
    }


}
extension LWMainViewController:LWTableBarDelegate{
    
    func composeBtnDidSelected() {
        
        
        print("代理过来的")
        
    }
    
    
}






